﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WcfRestLibrary
{
    public class ProductService:IProductService
    {
        public ProductDTO[] GetProducts()
        {
            using (NorthwindEntities db = new NorthwindEntities())
            {
                var query = from x in db.Products
                            select new ProductDTO
                            {
                                ProductName = x.ProductName,
                                CategoryName = x.Categories.CategoryName
                            };
                return query.ToArray();
            }
        }


        public ProductDTO[] GetProductsById(string categoryId)
        {
            using (NorthwindEntities db = new NorthwindEntities())
            {
                int y = int.Parse(categoryId);
                var query = from x in db.Products
                            where x.Categories.CategoryID == y
                            select new ProductDTO
                            {
                                ProductName = x.ProductName,
                                CategoryName = x.Categories.CategoryName
                            };
                return query.ToArray();
            }
        }
    }
}
